home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2004 #6 / Amiga Plus CD - 2004 - No. 06.iso / AmiSoft / Comm / misc / trsi-ftpd01.lha / FAME-FTPd / source / struct.h < prev    next >
C/C++ Source or Header  |  2004-04-24  |  10KB  |  289 lines

  1. /****************************************************************************************
  2.  *  PROJECT: FAME-FTPd
  3.  *     FILE: struct.h
  4.  *  PURPOSE: FTP related structures and global variables - main definitions for main.c
  5.  *  CREATED: 05-MAY-2003
  6.  * MODIFIED: 24-APR-2004
  7.  *   AUTHOR: Sascha 'SieGeL' Pfalz
  8.  ****************************************************************************************/
  9.  
  10. #include "global_defines.h"
  11.  
  12. struct Library                 *SocketBase         = NULL;    /* BSDsocket library */
  13. struct Library                 *UtilityBase         = NULL;    /* utility library */
  14. struct FAMELibrary        *FAMEBase             = NULL; /* FAME library */
  15. struct LocaleBase         *LocaleBase         = NULL;    /* Locale library */
  16. struct Library                 *SysLogBase         = NULL;    /* Optional logging to SysLogD */
  17. struct IntuitionBase    *IntuitionBase    =    NULL; /* Required for EasyRequest() */
  18. struct Locale                 *myloc                     = NULL; /* Locale catalog */
  19.  
  20. /*
  21.  *  Name of stats file
  22.  */
  23.  
  24. static    char statname[]="T:FAME-FTPd.stats";
  25.  
  26. /*
  27.  *  server_socket is our socket comming from InetD
  28.  */
  29.  
  30. LONG server_socket = -1;
  31.  
  32. /*
  33.  *  As we initialize bsdsocket.library we have to supply also our own error vars
  34.  */
  35.  
  36. int myerrno=-1,myherrno=-1;
  37.  
  38. /*
  39.  *  Name of our Program, is used for syslog() logging purposes
  40.  */
  41.  
  42. extern char *_ProgramName;
  43.  
  44. /*
  45.  *  Memory pointers for general I/O:
  46.  */
  47.  
  48. char *readbuf = NULL;                /* Command line buffer */
  49. char *readtmp = NULL;       /* Temporary copy buffer in readline() */
  50. char *uspbuf  = NULL;                /* Buffer used in usprintf() */
  51. APTR filebuf     = NULL;                /* Buffer for File I/O */
  52.  
  53.  
  54. /*  Our global FAME info structure, will be filled by Obtaining() FAME semaphore
  55.  *  and copy all required informations into this structure
  56.  */
  57.  
  58. struct FAMEInfos
  59.     {
  60.     char    BBSName[256];
  61.     char    SysOp[32];
  62.     long    FAMEVersion,
  63.                 FAMERevision,
  64.                 NodeCount;
  65.   ULONG FileULBytesHi,        // Only file transfer stats
  66.                 FileULBytesLo;
  67.   ULONG FileDLBytesHi,
  68.                 FileDLBytesLo;
  69.     ULONG    FilesUL,                    // Amount of Files transfered
  70.         FilesDL;
  71.     };
  72.  
  73. struct FAMEInfos *FameInfo=NULL;
  74.  
  75. /*
  76.  *  Global list structure for conference lists:
  77.  */
  78.  
  79. struct FConf
  80.     {
  81.   struct     FConf *next;
  82.     char    ConfName[32],
  83.                     ConfLocation[102],
  84.                     ULPath[102],
  85.                     DLPath[102],
  86.                     AddULPath[102],
  87.                     AddDLPath[102];
  88.     long        ConfNumber;
  89.     }*fconf1,*fconf2;
  90.  
  91. /*
  92.  *  Memorypointer for our Pool:
  93.  */
  94.  
  95. APTR mem_pool = NULL;
  96.  
  97. /*
  98.  *  Pointer to global FileInfoBlock structure (allocated in main() )
  99.  */
  100.  
  101. struct FileInfoBlock *fib = NULL;
  102.  
  103. /*
  104.  *  Preferences structure, used also by FAME-FTPdCFG:
  105.  */
  106.  
  107. struct FTPdConfig
  108.     {
  109.     char    HowToUploadFile[256];        // How-To-Upload file
  110.     ULONG    Flags1;                 // Option flags, see global_defines.h
  111.     char  UploadTempPath[256];        // Temporary upload path
  112.     long    FileNameLength,                    // Max. allowed filename length
  113.                 FileBufferSize;                    // Size for Buffer
  114.     ULONG    Timeout;                                // Timeout in seconds
  115.     char    IPFile[256],                        // Path to file containing IP Address/Hostname to use
  116.         TitleFile[256];         // Path to ASCII/ANSI file showing login gfx
  117.     int        PortLo,                                    // Passive port range, low value
  118.                 PortHi;                 // Passive port range, high value
  119.     char    LogFile[256];                        // Full filename for Logfile (not debug!)
  120.     long  MaxUsers;                                // If > 0 the Server must check for users online count
  121.     };
  122.  
  123. struct FTPdConfig *fconfig = NULL;
  124.  
  125. const char prefspath[]="FAME:ExternEnv/Doors/FAME-FTPd.cfg";
  126.  
  127. /*
  128.  *  UploadList contains all uploaded file that where recieved during a running session
  129.  */
  130.  
  131. struct FTPUploads
  132.     {
  133.     struct    MinNode Node;
  134.   char    FileName[128],
  135.                     FileDate[LEN_DATSTRING*2];
  136.     long    FileSize,
  137.                     ConfNum;
  138.     };
  139.  
  140. struct    MinList filelist;
  141.  
  142. /*
  143.  *  Server-Status structure describes current action of FTP-Server
  144.  */
  145.  
  146. struct FTPdStats
  147.     {
  148.     char    TaskAddress[10];            // FindTask(NULL)
  149.     long    UserNumber,                        // Usernumber
  150.                 CurrentConf;                    // Conference Number
  151.     char    ActionString[80];            // What the server currently doing
  152.     long    ULFiles;                 // How many files where uploaded
  153.     ULONG    ULBytesHi,                        // Hi Long for ul bytes
  154.                 ULBytesLo;                        // Lo Long for ul bytes
  155.   char    ConnectTime[18],            // Connect time of this user
  156.                 ULName[102];                    // Will be set to current upload file
  157.     };
  158.  
  159. struct FTPdStats *fstats = NULL;    // Used by current user
  160. struct FTPdStats *tmpptr = NULL;    // Used to find data inside datfile
  161.  
  162. /*
  163.  *  This structure is used at the end of session, it saves the upload states
  164.  *  as binary data for aCID-tOP so that uploads can be counted correctly.
  165.  */
  166.  
  167. struct AcidStats
  168.     {
  169.     long    UserNumber,
  170.                 ConfNumber,
  171.                 ULFiles;
  172.     ULONG    BytesHi,
  173.                 BytesLo;
  174.     };
  175.  
  176. /*
  177.  *  List of supported FTP commands according to RFC 959 / 2389
  178.  */
  179.  
  180. static char *commands[] =
  181.     {
  182.     "user",       /* USER: Passes the username */
  183.     "pass",            /* PASS: Passes the password for that user */
  184.     "type",            /* TYPE: Selects either ASCII or Binary transfer type */
  185.     "list",     /* LIST: Displays the current directory */
  186.     "cwd",      /*  CWD: Changes working directory */
  187.     "quit",            /* QUIT: Disconnects user and terminates */
  188.     "retr",            /* RETR: Send a file over network */
  189.     "stor",            /* STOR: Retrieve a file over network */
  190.     "port",            /* PORT: Use different data connection port */
  191.     "nlst",            /* NLST: New list format, same as LIST for this server */
  192.     "pwd",            /*  PWD: Print working directory */
  193.     "xpwd",            /* XPWD: Print working directory, for compatibility with 4.2BSD */
  194.     "mode",            /* MODE: Changes Mode, only STREAM is supported */
  195.     "pasv",            /* PASV: Turns on Passive mode */
  196.     "syst",            /* SYST: Returns system informations */
  197.     "noop",            /* NOOP: Does nothing but return OK */
  198.   "xcwd",            /* XCWD: Change working directory, for compatibility with 4.2BSD */
  199.   "cdup",            /* CDUP: Change to upper directory */
  200.     "size",            /* SIZE: Returns filesize of requested file (Extension) */
  201.   "stru",            /* STRU: Structure mode for Transfers, we ony support FILE. */
  202.     "abor",            /* ABOR: We hardly kick off all data connections..rfc959 says to do it more fancy, but who cares ;) */
  203.     "feat",            /* FEAT: Shows extensions that are supported by this server (RFC 2389) */
  204.   "clnt",            /* CLNT: Retrieves Client Program name and Version (Extension) */
  205.     "help",            /* HELP: Shows list of supported commands */
  206.     "stat",            /* STAT: Show statistics of current user */
  207.     NULL
  208.     };
  209.  
  210. /*
  211.  *  Corresponding Help messages
  212.  */
  213.  
  214. static char *cmdhelp[] =
  215.     {
  216.     "USER <sp> username",
  217.     "PASS [<sp> [password]]",
  218.     "TYPE <sp> { A | B | I | L }",
  219.     "LIST [ <sp> path-name ]",
  220.     "CWD [ <sp> directory-name ]",
  221.     "QUIT (terminate service)",
  222.     "RETR <sp> file-name",
  223.     "STOR <sp> file-name",
  224.     "PORT <sp> b0, b1, b2, b3, b4, b5",
  225.     "NLST [ <sp> path-name ]",
  226.     "PWD (return current directory)",
  227.     "XPWD (return current directory)",
  228.     "MODE (specify transfer mode)",
  229.     "PASV (set server in passive mode)",
  230.     "SYST (get type of operating system)",
  231.     "NOOP (No Operation)",
  232.     "XCWD [ <sp> directory-name ]",
  233.     "CDUP (change to parent directory)",
  234.     "SIZE <sp> path-name",
  235.     "STRU (specify file structure)",
  236.     "ABOR (abort operation)",
  237.     "FEAT (List extensions supported by this Server)",
  238.     "CLNT <sp>client_name <sp> client_version",
  239.     "HELP [ <sp> <string> ]",
  240.     "STAT (Show statistics of current user)",
  241.     NULL
  242.   };
  243.  
  244. /*
  245.  *  FTP reply codes:
  246.  */
  247.  
  248. char sending[]           = "150 Opening %s mode data connection for %s\r\n";
  249. char filesend[]            = "150 Opening %s mode data connection for '%s' (%ld bytes).\r\n";
  250. char typeok[]            = "200 Type %s OK\r\n";
  251. char portok[]            = "200 Port command okay\r\n";
  252. char okay[]              = "200 Ok\r\n";
  253. char stru_ok[]            = "200 STRU F ok.\r\n";
  254. char mode_ok[]            = "200 MODE S ok.\r\n";
  255. char size[]                    = "213 %lu\r\n";
  256. char systreply[]         = "215 AMIGA Type: L8\r\n";
  257. char banner[]            = "220- \r\n220- Welcome to %s FTP service (FAME V%ld.%ld)\r\n220- FAME-FTPd v%s [Build %ld] (c) 2003,2004 Sascha 'SieGeL/tRSi' Pfalz\r\n220- \r\n";
  258. char bye[]               = "221- \r\n221- \r\n\r221 Goodbye!\r\n";
  259. char abor_ok[]            = "225 ABOR command successful.\r\n";
  260. char rxok[]              = "226 File received OK\r\n";
  261. char txok[]              = "226 Transfer complete. Sent %ld Bytes.\r\n";
  262. char pasvcon[]            =    "227 Entering Passive Mode (%ld,%ld,%ld,%ld,%ld,%ld)\r\n";
  263. char logged[]            = "230 %s logged in, %s\r\n";
  264. char cwdmsg[]            = "250 \"%s\" is current directory\r\n";
  265. char pwdmsg[]            = "257 \"%s\" is current directory\r\n";
  266. char givepass[]          = "331 Enter Password\r\n";
  267. char ftperror[]          = "421 Service not available, closing control connection.\r\n";
  268. char noconn[]            = "425 Data connection reset\r\n";
  269. char noopendata[]     = "425 Can't open data connection.\r\n";
  270. char nopasv[]                = "425 Can't open passive connection (%ld)\r\n";
  271. char fileerror[]        = "451 Requested action aborted: local error in processing.\r\n";
  272. char unsupp[]            = "500 Unsupported command or option\r\n";
  273. char badcmd[]            = "500 Unknown command\r\n";
  274. char only8[]             = "501 Only logical bytesize 8 supported\r\n";
  275. char badtype[]           = "501 Unknown type \"%s\"\r\n";
  276. char badport[]           = "501 Bad port syntax\r\n";
  277. char unimp[]             = "502 Command not yet implemented\r\n";
  278. char mode_fail[]        = "502 Unimplemented MODE type.\r\n";
  279. char userfirst[]         = "503 Login with USER first.\r\n";
  280. char stru_fail[]         =    "504 Unimplemented STRU type.\r\n";
  281. char notlog[]            = "530 Please log in with USER and PASS\r\n";
  282. char noperm[]            = "550 Permission denied\r\n";
  283. char onlinewarn[]        = "550 Permission denied because you are currently online in FAME!\r\n";
  284. char filenotfound[] = "550 Requested action not taken. File not found\r\n";
  285. char nodir[]             = "553 Can't read directory \"%s\"\r\n";
  286. char cantmake[]          = "553 Can't create \"%s\": %s\r\n";
  287. char fileexists[]        = "553 File already exists.\r\n";
  288. char fnametoolong[]    = "553 Filename exeeds %ld characters, skipped!\r\n";
  289.